/* Title:		
 *
 * Project:     Category Search
 *
 * @ Link: 		http://...
 *
 * @ Email:		ivan_ling@hotmail.com
 *
 * @ Copyright: Copyright (c) 2008 mezimedia
 *
 * @ Author 	Ivan.ling
 *
 * @ Version 	1.0
 
 * @ last change time 2008-01-20 	
 */
package com.pub.util;


public class FilterUtils extends ConstantUtils
{

	/* main method
	 * @ param 	String[] : nothing param.
	 */
	public static void main(String args[])
	{
		String strCache = "(doc)$#;#^(www)#;#^(http)#;#^(httpwww)#;#(net)$#;#(com)$#;#(inc)$#;#(llc)$#;#(store)$#;#^(store)#;#(corp)$#;#^(shop)#;#(shop)$#;#(ltd)$#;#(onlinestore)$#;#(superstore)$#;#(company)$#;#(and)";
		String[] arrRegex = strCache.split("#;#");
		String strSource = "Music Bizness., ltd.com";
		//String strSource1 = "Fuzhou leadsport shoes co., ltd";
		
		System.out.println("out === " + FilterUtils.filterByRegxArray(strSource, arrRegex));
	}
	
	public FilterUtils()
	{
	}
	
	public static String deleteOtioseSpace(String source)
	{
	    return deleteOtioseChar(source, "  ");
	}

	public static String deleteOtioseChar(String strSource, String strChar)
	{
		String strDesc = strChar.substring(0, 1);
		while(true){
	        if(strSource.indexOf(strChar) == -1)
	            break;
	        else
	            strSource = strSource.replaceAll(strChar, strDesc);
	    }
		
	    return strSource.trim();
	}

   /* add slashes into input string.
    * @ param 	String 	strInput 	input string
    * @ return 	String
    */
   	public static String addCSlashes(String source)
   	{
   		return(source.replaceAll("\\\\","").replaceAll("\"","\\\\\"").replaceAll("'","\\\\'"));
	}
	
	public static String filterStr(String strSource, String[] arrFilter)
	{
		for(int i = 0; i < arrFilter.length; i++){
			strSource = strSource.replaceAll(arrFilter[i],"");
		}
		return strSource;
	}
	
	public static String filterByRegxArray(String strSource, String[] arrRegex)
	{
		for(int i = 0; i < arrRegex.length; i++){
			strSource = strSource.replaceAll(arrRegex[i], "");
		}
		return strSource;
	}
}